home *** CD-ROM | disk | FTP | other *** search
/ QuickTime for the Web (2nd Edition) / QuickTime for the Web (2nd Edition).iso / pc / AppleScript / QUICKTIME 5.0.2 SCRIPTS / Script Templates / QT 5 Droplet Template next >
Encoding:
Text File  |  2001-06-26  |  5.6 KB  |  162 lines

  1. -- AN EXAMPLE DROPLET WITH SETABLE PROPERTIES
  2.  
  3. property type_list : {"MooV"} -- the list of file types which will be processed
  4. property example_property_A : "On"
  5. property example_property_B : "On"
  6.  
  7. -- THE FOLLOWING ROUTINE APPEARS ONLY WHEN THE DROPLET IS DOUBLE-CLICKED
  8. on run
  9.     repeat
  10.         display dialog "QT Droplet Template" & return & return & ¬
  11.             "Example property A status: " & example_property_A & return & ¬
  12.             "Example property B status: " & example_property_B buttons {"Set Prefs", "Done"} default button 2
  13.         if the button returned of the result is "Done" then
  14.             exit repeat
  15.         else
  16.             display dialog "Set the status of the example property A to:" buttons {"Off", "On"} default button 2
  17.             set the example_property_A to the button returned of the result
  18.             
  19.             display dialog "Set the status of the example property B to:" buttons {"Off", "On"} default button 2
  20.             set the example_property_B to the button returned of the result
  21.         end if
  22.     end repeat
  23. end run
  24.  
  25. -- This droplet processes both files or folders of files dropped onto the applet
  26. on open these_items
  27.     -- CHECK THE VERSION OF QUICKTIME INSTALLED
  28.     -- this routine uses the gestaltVersion_info() sub-routine
  29.     copy my gestaltVersion_info("qtim", 8) to {QT_version, QT_string}
  30.     if the QT_version is less than "0502" then
  31.         display dialog "This script requires QuickTime 5.0.2 or higher." & ¬
  32.             return & return & "The currently installed version is: " & ¬
  33.             QT_string buttons {"Cancel"} default button 1
  34.     end if
  35.     -- EXAMINE AND PROCESS EACH DRAGGED-ON ITEM
  36.     repeat with i from 1 to the count of these_items
  37.         set this_item to (item i of these_items)
  38.         -- GET THE INFO FOR THIS ITEM
  39.         set the item_info to info for this_item
  40.         if folder of the item_info is true then
  41.             -- IF THE ITEM IS A FOLDER, CALL THE PROCESS FOLDER SUB-ROUTINE
  42.             process_folder(this_item)
  43.         else if (alias of the item_info is false) and ¬
  44.             (the file type of the item_info is in the type_list) then
  45.             -- IF THE ITEM IS NOT AN ALIAS AND ITS FILE TYPE IS IN THE LIST, 
  46.             -- THEN PROCESS THE ITEM
  47.             process_item(this_item)
  48.         end if
  49.     end repeat
  50. end open
  51.  
  52. -- this sub-routine processes folders
  53. on process_folder(this_folder)
  54.     -- GET A LIST OF FOLDER ITEMS
  55.     set these_items to list folder this_folder without invisibles
  56.     -- EXAMINE AND PROCESS EACH ITEM IN THE LIST
  57.     repeat with i from 1 to the count of these_items
  58.         set this_item to alias ((this_folder as text) & (item i of these_items))
  59.         set the item_info to info for this_item
  60.         if folder of the item_info is true then
  61.             process_folder(this_item)
  62.             -- this conditional checks for the creator code
  63.         else if (alias of the item_info is false) and ¬
  64.             (the file type of the item_info is in the type_list) then
  65.             process_item(this_item)
  66.         end if
  67.     end repeat
  68. end process_folder
  69.  
  70. -- this sub-routine processes files
  71. on process_item(this_item)
  72.     -- NOTE that the variable this_item is a file reference in alias format
  73.     -- FILE PROCESSING STATEMENTS GOES HERE
  74.     with timeout of 3600 seconds -- one hour per movie time limit
  75.         tell application "QuickTime Player"
  76.             activate
  77.             -- SUPPRESS AUTOPLAY AND AUTOPRESENT PROPERTIES IN ORDER TO WORK WITH THE MOVIE
  78.             my toggle_suppress(true)
  79.             -- STOP AND CLOSE ANY EXISTING MOVIES
  80.             stop every movie
  81.             close every movie saving no
  82.             try
  83.                 -- CHECK FOR QUICKTIME PRO
  84.                 if QuickTime Pro installed is false then
  85.                     set the target_URL to "http://www.apple.com/quicktime/download/"
  86.                     display dialog "This script requires QuickTime Pro." & return & return & ¬
  87.                         "If this computer is currently connected to the Internet, " & ¬
  88.                         "click the “Upgrade” button to visit the QuickTime Website at:" & ¬
  89.                         return & return & target_URL buttons {"Upgrade", "Cancel"} default button 2
  90.                     ignoring application responses
  91.                         tell application "Finder"
  92.                             open location target_URL
  93.                         end tell
  94.                     end ignoring
  95.                     error number -128
  96.                 end if
  97.                 -- OPEN THE ITEM
  98.                 open this_item
  99.                 tell movie 1
  100.                     -- IF THE MOVIE IS NOT EDITABLE, POST AN ALERT
  101.                     if saveable is false then
  102.                         error "This movie has previously been set so that it cannot be copied, edited, or saved."
  103.                     end if
  104.                     
  105.                     -- MOVIE PROCESSING STATEMENTS GO HERE
  106.                     
  107.                 end tell
  108.                 -- SAVE AND CLOSE THE MOVIE
  109.                 save movie 1
  110.                 close movie 1 saving no
  111.                 -- RESET THE APPLICATION SUPPRESS PROPERTY
  112.                 my toggle_suppress(false)
  113.             on error error_msg number error_num
  114.                 if the error_num is -128 then
  115.                     my toggle_suppress(false)
  116.                     error number -128
  117.                 else
  118.                     try
  119.                         beep
  120.                         display dialog error_msg buttons {"Cancel", "Continue"} default button 2 with icon 1
  121.                     on error
  122.                         my toggle_suppress(false)
  123.                         error number -128
  124.                     end try
  125.                 end if
  126.             end try
  127.             my toggle_suppress(false)
  128.             close movie 1 saving no
  129.         end tell
  130.     end timeout
  131. end process_item
  132.  
  133. on toggle_suppress(status_flag)
  134.     tell application "QuickTime Player"
  135.         set ignore auto play to the status_flag
  136.         set ignore auto present to the status_flag
  137.     end tell
  138. end toggle_suppress
  139.  
  140. -- THIS ROUTINE USES THE GESTALT COMMAND TO GET VERSION INFO
  141. on gestaltVersion_info(gestalt_code, string_length)
  142.     try
  143.         tell application "Finder" to ¬
  144.             copy my NumToHex((computer gestalt_code), ¬
  145.                 string_length) to {a, b, c, d}
  146.         set the numeric_version to {a, b, c, d} as string
  147.         if a is "0" then set a to ""
  148.         set the version_string to (a & b & "." & c & "." & d) as string
  149.         return {numeric_version, version_string}
  150.     on error
  151.         return {"", "unknown"}
  152.     end try
  153. end gestaltVersion_info
  154.  
  155. on NumToHex(hexData, stringLength)
  156.     set hexString to {}
  157.     repeat with i from stringLength to 1 by -1
  158.         set hexString to ((hexData mod 16) as string) & hexString
  159.         set hexData to hexData div 16
  160.     end repeat
  161.     return (hexString as string)
  162. end NumToHex